package com.huluobo.module_city.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData
import com.huluobo.appbase.network.HttpErrorDeal
import com.huluobo.module_city.repo.CityRepo
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flow

/**
 * Created by lc on 2022/12/28.
 * City的ViewModel
 */
class CityDataViewModel : ViewModel() {
    fun loadCityData() = flow {
        val data = CityRepo().loadCityData()
        emit(data)
    }.catch {
        if (it is Exception) {
            //使用同一的异常进行处理
            HttpErrorDeal.dealHttpError(it)
        }
        emit(null)
    }.asLiveData()
}